package net.jkdmanager.agent.services.ping;

import net.jkdmanager.agent.services.agent.AgentStatusService;
import net.jkdmanager.common.api.messages.AgentStatusMessage;
import net.jkdmanager.common.services.messaging.MessagingService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

@Service("pingService")
public class PingServiceImpl {

	@Autowired
	private AgentStatusService agentStatusService; 

	@Autowired
	private MessagingService messagingService; 
	
	@Value("#{systemProperties.agentId}")
	private String agentId;
		
	@Scheduled(fixedRate=5000)
	public void sendPing() {

		final AgentStatusMessage agentStatus = new AgentStatusMessage();
		agentStatus.setAgentId(agentId);
		agentStatus.setStatus(agentStatusService.getStatus());
	
		messagingService.sendMessage(agentStatus);
		
	}

}
